package com.homestay.service.impl;

import com.homestay.beans.Home;
import com.homestay.dao.HomeDao;
import com.homestay.dao.impl.HomeDaoImpl;
import com.homestay.exception.UsedException;
import com.homestay.service.HomeService;

import java.util.Collections;
import java.util.List;

public class HomeServiceImpl implements HomeService {

    HomeDao homeDao = new HomeDaoImpl();

    @Override
    public int addHome(Home home) {
        return homeDao.addHome(home);
    }

    @Override
    public int deleteHome(int id) throws UsedException {
        Home home = homeDao.getHomeById(id);
        if("已入住".equals(home.getState())) {
            throw new UsedException("该房间已被预订，无法删除");
        }
        return homeDao.deleteHome(id);
    }

    @Override
    public int updateHome(Home home) {
        return homeDao.updateHome(home);
    }

    @Override
    public Home getHomeById(int id) {
        return homeDao.getHomeById(id);
    }

    @Override
    public List<Home> getAllHomes(String num) {
        return homeDao.getAllHomes(num);
    }

    @Override
    public List<Home> getHomesByState(String state) {
        return homeDao.getHomesByState(state);
    }

    @Override
    public int updateHomeState(int id, String state) {
        return homeDao.updateHomeState(id, state);
    }
}
